package com.yt.app.api.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

public class CookieUtils {

    public static String get(Cookie[] cookies, String key) {
        String result = null;
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(key)) {
                    result = cookie.getValue();
                }
            }
        }
        
        return result;
    }

    public static Cookie createCookie(String name, String value){
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        return cookie;
    }
    
    public static void delCookie(HttpServletResponse response, String name){
        Cookie cookie = new Cookie(name, null);
        cookie.setMaxAge(0);
        cookie.setPath("/");
        response.addCookie(cookie);
    }
}
